/**
 * @Title: StoDayInfoContorller.java
 * @Package cn.com.klun.tjy.controller
 * @Description: TBL_STO_DAY_INFO的控制器
 * @author GOME
 * @date Thu Jan 25 18:27:19 CST 2018
 * @company cn.com.gome
 * @version V1.0
 */

package cn.com.klun.tjy.admin.controller;

import cn.com.klun.tjy.admin.common.AbstractAdminController;
import cn.com.klun.tjy.admin.common.EntityPersistenceLayerService;
import cn.com.klun.tjy.common.baseInterface.PersistenceLayerSerMapper;
import cn.com.klun.tjy.common.basePojo.PageQueryEntitys;
import org.apache.commons.lang.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import org.springframework.ui.Model;
import java.util.List;
import cn.com.klun.tjy.dao.entity.TblStoDayInfo;
import cn.com.klun.tjy.vo.StoDayInfoVo;
import cn.com.klun.tjy.dao.mapper.edit.TblStoDayInfoEditMapper;
import cn.com.klun.tjy.dao.mapper.ser.TblStoDayInfoSerMapper;

/**
 * @ClassName: StoDayInfoContorller
 * @Description: TBL_STO_DAY_INFO的控制器
 * @author
 * @date 2015年2月10日 下午2:35:34
 */
@Controller
@RequestMapping("/stodayinfo")
public class StoDayInfoController extends AbstractAdminController {

	@Autowired
	private EntityPersistenceLayerService entityPersistenceLayerService;

	@Autowired
	private TblStoDayInfoEditMapper tblStoDayInfoEditMapper;

	@Autowired
	private TblStoDayInfoSerMapper tblStoDayInfoSerMapper;

	@RequestMapping("/inits")
	public String init(Model model,HttpServletRequest request, HttpServletResponse response) {

		return "stodayinfo/inits";
	}

	@RequestMapping("/search")
	public void search(@ModelAttribute("pageQueryEntitys") PageQueryEntitys pageQueryEntitys, HttpServletRequest request, HttpServletResponse response) {
		try {
			pageQueryEntitys.setEntityClassName("TblStoDayInfo");
			String id = request.getParameter("id");
			if (StringUtils.isNotEmpty(id)) {
				pageQueryEntitys.addF("id", id);
			}
			String stoId = request.getParameter("stoId");
			if (StringUtils.isNotEmpty(stoId)) {
				pageQueryEntitys.addF("stoId", stoId);
			}
			String trnDate = request.getParameter("trnDate");
			if (StringUtils.isNotEmpty(trnDate)) {
				pageQueryEntitys.addF("trnDate", trnDate);
			}
			String starPri = request.getParameter("starPri");
			if (StringUtils.isNotEmpty(starPri)) {
				pageQueryEntitys.addF("starPri", starPri);
			}
			String maxPri = request.getParameter("maxPri");
			if (StringUtils.isNotEmpty(maxPri)) {
				pageQueryEntitys.addF("maxPri", maxPri);
			}
			String minPri = request.getParameter("minPri");
			if (StringUtils.isNotEmpty(minPri)) {
				pageQueryEntitys.addF("minPri", minPri);
			}
			String endPri = request.getParameter("endPri");
			if (StringUtils.isNotEmpty(endPri)) {
				pageQueryEntitys.addF("endPri", endPri);
			}
			String trnNum = request.getParameter("trnNum");
			if (StringUtils.isNotEmpty(trnNum)) {
				pageQueryEntitys.addF("trnNum", trnNum);
			}
			String trnAmount = request.getParameter("trnAmount");
			if (StringUtils.isNotEmpty(trnAmount)) {
				pageQueryEntitys.addF("trnAmount", trnAmount);
			}
			String turnRate = request.getParameter("turnRate");
			if (StringUtils.isNotEmpty(turnRate)) {
				pageQueryEntitys.addF("turnRate", turnRate);
			}
			String qtityRelaRatio = request.getParameter("qtityRelaRatio");
			if (StringUtils.isNotEmpty(qtityRelaRatio)) {
				pageQueryEntitys.addF("qtityRelaRatio", qtityRelaRatio);
			}
			String peRatio = request.getParameter("peRatio");
			if (StringUtils.isNotEmpty(peRatio)) {
				pageQueryEntitys.addF("peRatio", peRatio);
			}
			String pbRatio = request.getParameter("pbRatio");
			if (StringUtils.isNotEmpty(pbRatio)) {
				pageQueryEntitys.addF("pbRatio", pbRatio);
			}
			String allMarketVal = request.getParameter("allMarketVal");
			if (StringUtils.isNotEmpty(allMarketVal)) {
				pageQueryEntitys.addF("allMarketVal", allMarketVal);
			}
			String cirMarketVal = request.getParameter("cirMarketVal");
			if (StringUtils.isNotEmpty(cirMarketVal)) {
				pageQueryEntitys.addF("cirMarketVal", cirMarketVal);
			}
			String mainInto = request.getParameter("mainInto");
			if (StringUtils.isNotEmpty(mainInto)) {
				pageQueryEntitys.addF("mainInto", mainInto);
			}
			String mainOut = request.getParameter("mainOut");
			if (StringUtils.isNotEmpty(mainOut)) {
				pageQueryEntitys.addF("mainOut", mainOut);
			}
			String mainOutIn = request.getParameter("mainOutIn");
			if (StringUtils.isNotEmpty(mainOutIn)) {
				pageQueryEntitys.addF("mainOutIn", mainOutIn);
			}
			String sOrderInto = request.getParameter("sOrderInto");
			if (StringUtils.isNotEmpty(sOrderInto)) {
				pageQueryEntitys.addF("sOrderInto", sOrderInto);
			}
			String sOrderOut = request.getParameter("sOrderOut");
			if (StringUtils.isNotEmpty(sOrderOut)) {
				pageQueryEntitys.addF("sOrderOut", sOrderOut);
			}
			String bOrderInto = request.getParameter("bOrderInto");
			if (StringUtils.isNotEmpty(bOrderInto)) {
				pageQueryEntitys.addF("bOrderInto", bOrderInto);
			}
			String bOrderOut = request.getParameter("bOrderOut");
			if (StringUtils.isNotEmpty(bOrderOut)) {
				pageQueryEntitys.addF("bOrderOut", bOrderOut);
			}
			String mOrderInto = request.getParameter("mOrderInto");
			if (StringUtils.isNotEmpty(mOrderInto)) {
				pageQueryEntitys.addF("mOrderInto", mOrderInto);
			}
			String mOrderOut = request.getParameter("mOrderOut");
			if (StringUtils.isNotEmpty(mOrderOut)) {
				pageQueryEntitys.addF("mOrderOut", mOrderOut);
			}
			String lOrderInto = request.getParameter("lOrderInto");
			if (StringUtils.isNotEmpty(lOrderInto)) {
				pageQueryEntitys.addF("lOrderInto", lOrderInto);
			}
			String lOrderOut = request.getParameter("lOrderOut");
			if (StringUtils.isNotEmpty(lOrderOut)) {
				pageQueryEntitys.addF("lOrderOut", lOrderOut);
			}
			String outerDisc = request.getParameter("outerDisc");
			if (StringUtils.isNotEmpty(outerDisc)) {
				pageQueryEntitys.addF("outerDisc", outerDisc);
			}
			String innerIdsc = request.getParameter("innerIdsc");
			if (StringUtils.isNotEmpty(innerIdsc)) {
				pageQueryEntitys.addF("innerIdsc", innerIdsc);
			}
			String lockFlag = request.getParameter("lockFlag");
			if (StringUtils.isNotEmpty(lockFlag)) {
				pageQueryEntitys.addF("lockFlag", lockFlag);
			}
			String lockTime = request.getParameter("lockTime");
			if (StringUtils.isNotEmpty(lockTime)) {
				pageQueryEntitys.addF("lockTime", lockTime);
			}
			String lockCounts = request.getParameter("lockCounts");
			if (StringUtils.isNotEmpty(lockCounts)) {
				pageQueryEntitys.addF("lockCounts", lockCounts);
			}
			String taskUpdateTime = request.getParameter("taskUpdateTime");
			if (StringUtils.isNotEmpty(taskUpdateTime)) {
				pageQueryEntitys.addF("taskUpdateTime", taskUpdateTime);
			}
			pageQueryEntitys = entityPersistenceLayerService.queryPageVoList((PersistenceLayerSerMapper) tblStoDayInfoSerMapper, pageQueryEntitys);
		} catch (Exception e) {
			logger.error(" TBL_STO_DAY_INFO的控制器执行异常【search】",e);
		}
		ajaxJsonPage(JSONArray.fromObject(pageQueryEntitys.getList()).toString(),pageQueryEntitys.getTotalCount(),response);
	}

	@RequestMapping("/select")
	public void select(HttpServletRequest request, HttpServletResponse response) {
		try {
			TblStoDayInfo obj = new TblStoDayInfo();
			List<TblStoDayInfo> list = tblStoDayInfoSerMapper.queryList(obj);
			ajaxJsonMessage(response,JSONArray.fromObject(list).toString());
		} catch (Exception e) {
			logger.error(" TBL_STO_DAY_INFO的控制器执行异常【select】",e);
		}
	}

	@RequestMapping("/add")
	public String add(HttpServletRequest request, HttpServletResponse response,Model model){
		model.addAttribute("resultType", "add");
		return "stodayinfo/add";
	}

	@RequestMapping("/save")
	public String save(@ModelAttribute("enitty") TblStoDayInfo enitty,HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			tblStoDayInfoEditMapper.save(enitty);
			model.addAttribute("messages", "温馨提示：添加成功！");
			model.addAttribute("resultStatus", "true");
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：添加异常:" + e.getMessage());
			logger.error(" stodayinfo的控制器执行异常【save】",e);
		}
		model.addAttribute("ADN_ADD_URL", "stodayinfo/add.dhtml");
		return "success";

	}

	@RequestMapping("/query")
	public String query(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultType", "edit");
			model.addAttribute("resultStatus", "false");
			TblStoDayInfo enitty = new TblStoDayInfo();
			enitty.setId(Integer.valueOf(request.getParameter("id_key")));
			enitty = (TblStoDayInfo) tblStoDayInfoSerMapper.queryObj(enitty);
			if (enitty != null){
				model.addAttribute("enitty", enitty);
				model.addAttribute("resultStatus", "true");
				return "stodayinfo/add";
			}
			model.addAttribute("messages", "温馨提示：没有查询到符合条件的记录！");

		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：查询异常:" + e.getMessage());
			logger.error(" stodayinfo的控制器执行异常【query】",e);
		}
		return "success";
	}

	@RequestMapping("/edit")
	public String edit(@ModelAttribute("enitty") TblStoDayInfo enitty,HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			int count = tblStoDayInfoEditMapper.edit(enitty);
			if (count == 0) {
				model.addAttribute("messages", "温馨提示：修改失败！");
			} else {
				model.addAttribute("messages", "温馨提示：修改成功！");
				model.addAttribute("resultStatus", "true");
				TblStoDayInfo enittyNew = new TblStoDayInfo();
				enittyNew.setId(enitty.getId());
				enittyNew = (TblStoDayInfo) tblStoDayInfoSerMapper.queryObj(enittyNew);
				model.addAttribute("enitty", enittyNew);
				model.addAttribute("resultStatus", "true");
				model.addAttribute("resultType", "edit");
				return "stodayinfo/add";
			}
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：修改异常:" + e.getMessage());
			logger.error(" stodayinfo的控制器执行异常【edit】",e);
		}
		return "success";
	}

	@RequestMapping("/del")
	public void del(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			int count = tblStoDayInfoEditMapper.del(Arrays.asList(request.getParameter("id_key").split(",")));
			if (count == 0) {
				ajaxJsonMessage(response,"0002","温馨提示：没有删除到符合条件的记录！","");
			} else {
				ajaxJsonMessage(response,"0000","温馨提示：删除成功！","");
			}
		} catch (Exception e) {
			ajaxJsonMessage(response,"0002","温馨提示：删除失败！","");
			logger.error(" stodayinfo的控制器执行异常【del】",e);
		}
	}

	@RequestMapping("/view")
	public String view(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultType", "view");
			model.addAttribute("resultStatus", "false");
			TblStoDayInfo enitty = new TblStoDayInfo();
			enitty.setId(Integer.valueOf(request.getParameter("id_key")));
			StoDayInfoVo vo = (StoDayInfoVo) tblStoDayInfoSerMapper.queryVo(enitty);
			if (vo != null){
				model.addAttribute("enitty", vo);
				model.addAttribute("resultStatus", "true");
			}else{
				model.addAttribute("messages", "温馨提示：没有查询到符合条件的记录！");
			}
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：查询异常:" + e.getMessage());
			logger.error(" stodayinfo的控制器执行异常【view】",e);
		}
		return "stodayinfo/add";
	}

}
